<?php


namespace Drupal\shusy_product_category\ViewsController\handler\filter;


use Drupal\shusy_category\Entity\ShusyCategory;

class ShusyProductCategoryCategoriesViewsFilter extends \views_handler_filter_many_to_one {

  public function get_value_options() {
    if (!isset($this->value_options)) {
      $this->value_title = "分类";
      $options = [];
      $categories = shusy_category_load_multiple(FALSE, [
        'status' => 1,
        'parent' => 0,
      ]);
      foreach ($categories as $category) {
        if ($category instanceof ShusyCategory) {
          $categories2 = shusy_category_load_multiple(FALSE, [
            'status' => 1,
            'parent' => $category->id,
          ]);
          foreach ($categories2 as $item) {
            if ($item instanceof ShusyCategory) {
              $options[$category->name][$item->id] = $item->name;
            }
          }
        }
      }
      $this->value_options = $options;
    }
  }

}
